package com.zzxz.practicaltrainingsys.mapper;

import com.zzxz.practicaltrainingsys.entity.Image;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ImageMapper {

    // 更新头像路径
    @Update("<script>" +
            "UPDATE " +
            "<choose>" +
            "   <when test='role == \"admin\"'> admin SET admin_image = #{imagePath} </when>" +
            "   <when test='role == \"teacher\"'> teacher SET teacher_image = #{imagePath} </when>" +
            "   <when test='role == \"student\"'> student SET student_image = #{imagePath} </when>" +
            "</choose>" +
            "WHERE " +
            "<choose>" +
            "   <when test='role == \"admin\"'> admin_id = #{userId} </when>" +
            "   <when test='role == \"teacher\"'> teacher_id = #{userId} </when>" +
            "   <when test='role == \"student\"'> student_id = #{userId} </when>" +
            "</choose>" +
            "</script>")
    int updateImagePath(Image image);

    // 获取头像路径
    @Select("<script>" +
            "SELECT " +
            "<choose>" +
            "   <when test='role == \"admin\"'> admin_image </when>" +
            "   <when test='role == \"teacher\"'> teacher_image </when>" +
            "   <when test='role == \"student\"'> student_image </when>" +
            "</choose> AS imagePath " +
            "FROM " +
            "<choose>" +
            "   <when test='role == \"admin\"'> admin </when>" +
            "   <when test='role == \"teacher\"'> teacher </when>" +
            "   <when test='role == \"student\"'> student </when>" +
            "</choose>" +
            "WHERE " +
            "<choose>" +
            "   <when test='role == \"admin\"'> admin_id = #{userId} </when>" +
            "   <when test='role == \"teacher\"'> teacher_id = #{userId} </when>" +
            "   <when test='role == \"student\"'> student_id = #{userId} </when>" +
            "</choose>" +
            "</script>")
    String getImagePath(Image image);
}